<!DOCTYPE html>












  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">









  
  
    
  
  <link rel="stylesheet" media="all" href="https://cdnjs.cloudflare.com/ajax/libs/Han/3.3.0/han.min.css">




<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">



















  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






  

<link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=6.3.0" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=6.3.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=6.3.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=6.3.0">


  <link rel="mask-icon" href="/images/logo.svg?v=6.3.0" color="#222">









<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '6.3.0',
    sidebar: {"position":"left","display":"hide","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="jar命令.jar（Java Archive）是Java中的一种归档文件格式，只要安装了 JDK ，都可以使用 jar 命令将多个文件打包成一个 .jar 格式的 jar 包或者 war 包，就像 Linux 里的 tar 命令一样，以下为 jar 命令的参数： 1234567891011121314151617181920212223242526用法: jar &amp;#123;ctxui&amp;#125;">
<meta name="keywords" content="java,jar">
<meta property="og:type" content="article">
<meta property="og:title" content="jar命令">
<meta property="og:url" content="http://codertang.com/2021/06/11/jar-command/index.html">
<meta property="og:site_name" content="Tonny&#39;s Blog">
<meta property="og:description" content="jar命令.jar（Java Archive）是Java中的一种归档文件格式，只要安装了 JDK ，都可以使用 jar 命令将多个文件打包成一个 .jar 格式的 jar 包或者 war 包，就像 Linux 里的 tar 命令一样，以下为 jar 命令的参数： 1234567891011121314151617181920212223242526用法: jar &amp;#123;ctxui&amp;#125;">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2021-06-11T07:58:28.613Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="jar命令">
<meta name="twitter:description" content="jar命令.jar（Java Archive）是Java中的一种归档文件格式，只要安装了 JDK ，都可以使用 jar 命令将多个文件打包成一个 .jar 格式的 jar 包或者 war 包，就像 Linux 里的 tar 命令一样，以下为 jar 命令的参数： 1234567891011121314151617181920212223242526用法: jar &amp;#123;ctxui&amp;#125;">






  <link rel="canonical" href="http://codertang.com/2021/06/11/jar-command/">



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>jar命令 | Tonny's Blog</title>
  









  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Tonny's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <p class="site-subtitle">莫等闲, 白了少年头, 空悲切</p>
      
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">
    <a href="/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">
    <a href="/tags/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">
    <a href="/categories/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">
    <a href="/archives/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>
  </li>

      
      
    </ul>
  

  
    

  

  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://codertang.com/2021/06/11/jar-command/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Tonny Yi">
      <meta itemprop="description" content="Coding, Life, Zen">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Tonny's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">jar命令
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2021-06-11 14:28:27 / 修改时间：15:58:28" itemprop="dateCreated datePublished" datetime="2021-06-11T14:28:27+08:00">2021-06-11</time>
            

            
              

              
            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/java/" itemprop="url" rel="index"><span itemprop="name">java</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        <h2 id="jar命令"><a href="#jar命令" class="headerlink" title="jar命令"></a>jar命令</h2><p>.jar（Java Archive）是Java中的一种归档文件格式，只要安装了 JDK ，都可以使用 jar 命令将多个文件打包成一个 .jar 格式的 jar 包或者 war 包，就像 Linux 里的 tar 命令一样，以下为 jar 命令的参数：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">用法: jar &#123;ctxui&#125;[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] files ...</span><br><span class="line">选项:</span><br><span class="line">    -c  创建新档案</span><br><span class="line">    -t  列出档案目录</span><br><span class="line">    -x  从档案中提取指定的 (或所有) 文件</span><br><span class="line">    -u  更新现有档案</span><br><span class="line">    -v  在标准输出中生成详细输出</span><br><span class="line">    -f  指定档案文件名</span><br><span class="line">    -m  包含指定清单文件中的清单信息</span><br><span class="line">    -n  创建新档案后执行 Pack200 规范化</span><br><span class="line">    -e  为捆绑到可执行 jar 文件的独立应用程序</span><br><span class="line">        指定应用程序入口点</span><br><span class="line">    -0  仅存储; 不使用任何 ZIP 压缩</span><br><span class="line">    -P  保留文件名中的前导 '/' (绝对路径) 和 ".." (父目录) 组件</span><br><span class="line">    -M  不创建条目的清单文件</span><br><span class="line">    -i  为指定的 jar 文件生成索引信息</span><br><span class="line">    -C  更改为指定的目录并包含以下文件</span><br><span class="line">如果任何文件为目录, 则对其进行递归处理。</span><br><span class="line">清单文件名, 档案文件名和入口点名称的指定顺序</span><br><span class="line">与 'm', 'f' 和 'e' 标记的指定顺序相同。</span><br><span class="line"></span><br><span class="line">示例 1: 将两个类文件归档到一个名为 classes.jar 的档案中:</span><br><span class="line">       jar cvf classes.jar Foo.class Bar.class</span><br><span class="line">示例 2: 使用现有的清单文件 'mymanifest' 并</span><br><span class="line">           将 foo/ 目录中的所有文件归档到 'classes.jar' 中:</span><br><span class="line">       jar cvfm classes.jar mymanifest -C foo/ .</span><br></pre></td></tr></table></figure>
<h2 id="查看jar包内容"><a href="#查看jar包内容" class="headerlink" title="查看jar包内容"></a>查看jar包内容</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">jar -tvf xx.jar</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 如果你想查看解压一个jar的详细过程，而这个jar包又很大，屏幕信息会一闪而过，这时你可以把列表输出到一个文件中，慢慢欣赏！</span></span><br><span class="line">jar -tvf xx.jar&gt;files.txt</span><br></pre></td></tr></table></figure>
<h2 id="解压jar-war文件"><a href="#解压jar-war文件" class="headerlink" title="解压jar/war文件"></a>解压jar/war文件</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 解压全部文件</span></span><br><span class="line">jar -xvf xx.jar</span><br><span class="line">jar -xvf xx.war</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 提取指定文件，提取后，文件会被放到与其package声明相同的目录结构下</span></span><br><span class="line">java -xvf xx.jar com/test/Test.class</span><br></pre></td></tr></table></figure>
<h2 id="打包jar-war文件"><a href="#打包jar-war文件" class="headerlink" title="打包jar/war文件"></a>打包jar/war文件</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 把当前目录的所有文件都打进去</span></span><br><span class="line">jar -cvf test.jar *</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 只打包某个文件或目录，后面接文件、目录即可</span></span><br><span class="line">jar -cvf test.jar WEB-INF/ com/</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 打包时不压缩内容</span></span><br><span class="line">jar -cvf0 test.jar *</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 先切换工作目录再打包  先切换到<span class="built_in">test</span>目录再执行jar命令</span></span><br><span class="line">jar -cvf test.jar * -C test/</span><br></pre></td></tr></table></figure>
<h3 id="manifest文件"><a href="#manifest文件" class="headerlink" title="manifest文件"></a>manifest文件</h3><p>打包时会默认创建<code>mainifest.mf</code>文件，我们也可以选择不生成<code>manifest.mf</code>文件，或者使用已有的<code>manifest.mf</code>文件，特别是<code>springboot</code>打包出来的jar包中，<code>manifest.mf</code>包含很多扩展信息，我们必须要复用，否则会跑不起来。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 不生成manifest.mf文件</span></span><br><span class="line">jar -cvfM test.jar *</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 复用已有的manifest.mf文件</span></span><br><span class="line">jar -cvfm test.jar mymanifest.mf *</span><br></pre></td></tr></table></figure>
<h4 id="manifest-mf文件规范"><a href="#manifest-mf文件规范" class="headerlink" title="manifest.mf文件规范"></a><code>manifest.mf</code>文件规范</h4><blockquote>
<ul>
<li>不能有空行和空格的地方：第一行不可以是空行，行与行之间不能有空行，每行的行尾不可以有空格</li>
<li>一定要有空行的地方，最后一行得是空行</li>
<li>一定有空格的地方：key: value 在分号后面一定要写一个空格</li>
<li>每行不能超过七十多的字符</li>
<li>Class-Path里边的内容用空格分隔而不是逗号或者分号</li>
</ul>
</blockquote>
<p>普通示例</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">Manifest-Version: 1.0</span><br><span class="line">Created-By: JDJ example</span><br><span class="line">Class-Path: mail.jar activation.jar</span><br><span class="line">Main-Class: com.test.PackageClass</span><br><span class="line">Name: com/example/myapp/</span><br><span class="line">Specification-Title: MyApp</span><br><span class="line">Specification-Version: 2.4</span><br><span class="line">Specification-Vendor: example.com</span><br><span class="line">Implementation-Title: com.example.myapp</span><br><span class="line">Implementation-Version: 2002-03-05-A</span><br><span class="line">Implementation-Vendor: example.com</span><br></pre></td></tr></table></figure>
<p>springboot打包出来的manifest.mf文件示例</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">Manifest-Version: 1.0</span><br><span class="line">Implementation-Title: znyj-server</span><br><span class="line">Implementation-Version: 0.0.1-FY1013</span><br><span class="line">Built-By: tonnyyi</span><br><span class="line">Implementation-Vendor-Id: com.iflytek</span><br><span class="line">Spring-Boot-Version: 2.1.2.RELEASE</span><br><span class="line">Main-Class: org.springframework.boot.loader.JarLauncher</span><br><span class="line">Start-Class: com.iflytek.znyjserver.ZnyjServerApplication</span><br><span class="line">Spring-Boot-Classes: BOOT-INF/classes/</span><br><span class="line">Spring-Boot-Lib: BOOT-INF/lib/</span><br><span class="line">Created-By: Apache Maven 3.6.3</span><br><span class="line">Build-Jdk: 1.8.0_261</span><br><span class="line">Implementation-URL: https://projects.spring.io/spring-boot/#/spring-bo</span><br><span class="line"> ot-starter-parent/znyj-server</span><br></pre></td></tr></table></figure>
<p>属性介绍</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">Manifest-Version:</span><br><span class="line">用来定义manifest文件的版本，例如：Manifest-Version: 1.0</span><br><span class="line"></span><br><span class="line">Created-By:</span><br><span class="line">声明该文件的生成者，一般该属性是由jar命令行工具生成的，例如：Created-By: Apache Ant 1.5.1</span><br><span class="line"></span><br><span class="line">Main-Class</span><br><span class="line">定义jar文件的入口类，该类必须是一个可执行的类(包含main方法的类)，一旦定义了该属性即可通过 java -jar x.jar来运行该jar文件。</span><br><span class="line">运行Jar: java -jar test.jar</span><br><span class="line">当运行上述命令时JVM将在test.jar文件中的MANIFEST.MF文件中查找Main-Class属性的值，并尝试运行该类。如果在yveshe.jar文件中未包含Main-Class属性，则上述命令将生成错误。</span><br><span class="line"></span><br><span class="line">Class-Path:</span><br><span class="line">指定jar包的依赖关系，class loader会依据这个路径来搜索class.默认是相对路径,相对该jar所在的父文件夹.</span><br><span class="line">可以在其manifest 文件中为JAR文件设置CLASSPATH。属性名称叫作类路径，必须在自定义清单文件中指定。 它是一个空格分隔的jar文件，zip文件和目录的列表。(不区分系统都是以空格来分隔多个jar文件)以下是一个属性配置例子:</span><br><span class="line">Class-Path: reference1.jar file:/c:/book/ http://www.test.com/reference2.jar</span><br><span class="line">这条命令配置了该test.jar依赖了三个jar:</span><br><span class="line">一个JAR文件reference1.jar，一个使用文件协议文件的目录：c:/book/和另一个使用HTTP协议的JAR文件http://www.test.com/reference2.jar</span><br><span class="line">注意: 当使用java命令使用-jar(比如java -jar test.jar)选项运行JAR文件时，将忽略Jar中 manifest文件之外的任何CLASSPATH设置。</span><br><span class="line"></span><br><span class="line">Sealed:</span><br><span class="line">密封 JAR 文件中的一个包意味着在这个包中定义的所有类都必须在同一个 JAR 文件中找到。这使包的作者可以增强打包类之间的版本一致性。密封还提供了防止代码篡改的手段。</span><br><span class="line">要密封包，需要在 JAR 的 manifest 文件中为包添加一个 Name 头，然后加上值为“true”的 Sealed 头。与可执行的 JAR 一样，可以在创建 JAR 时，通过指定一个具有适当头元素的 manifest 文件密封一个 JAR，如下所示：</span><br><span class="line">Name: com/yveshe/</span><br><span class="line">Sealed: true</span><br><span class="line">Name 头标识出包的相对路径名。它以一个“/”结束以与文件名区别。在 Name 头后面第一个空行之前的所有头都作用于在 Name 头中指定的文件或者包。在上述例子中，因为 Sealed 头出现在 Name 头后并且中间没有空行，所以 Sealed 头将被解释为只应用到包 com/yveshe上。如果试图从密封包所在的 JAR 文件以外的其他地方装载密封包中的一个类，那么 JVM 将抛出一个SecurityException 。文件头Name的值为该封装的相对路径名。注意，该路径名由‘/’结束以区别于文件名。</span><br></pre></td></tr></table></figure>
<h2 id="替换jar包内文件"><a href="#替换jar包内文件" class="headerlink" title="替换jar包内文件"></a>替换jar包内文件</h2><p>要想替换文件，在linux下可以把jar包解压，替换后再打成jar，麻烦。其实可以使用jar命令直接替换。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 一定先建好目录结构com/<span class="built_in">test</span>，然后把test.class文件放入<span class="built_in">test</span>目录，再打包</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> mkdir -vp com/<span class="built_in">test</span></span></span><br><span class="line">jar -uvf test.jar com/test/test.class</span><br></pre></td></tr></table></figure>
<blockquote>
<p><strong>注意</strong>：<code>test.class</code>文件一定要按其package声明，放到对应的目录层级下，然后再打包，否则打包后，其在jar包中的路径会与其package声明不一致，从而导致出错。</p>
</blockquote>
<h2 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 编译时依赖其他jar包</span></span><br><span class="line">javac -cp b.jar lib/a.jar XX.java</span><br></pre></td></tr></table></figure>
<p>反编译</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 只看方法声明</span></span><br><span class="line">javap org/springframework/boot/loader/ExecutableArchiveLauncher.class</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 输出方法体，以java字节码的形式</span></span><br><span class="line">javap -c org/springframework/boot/loader/ExecutableArchiveLauncher.class</span><br></pre></td></tr></table></figure>

      
    </div>

    

    
    
    

    

    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Tonny Yi</li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://codertang.com/2021/06/11/jar-command/" title="jar命令">http://codertang.com/2021/06/11/jar-command/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc/4.0/" rel="external nofollow" target="_blank">CC BY-NC 4.0</a> 许可协议。转载请注明出处！</li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/java/" rel="tag"># java</a>
          
            <a href="/tags/jar/" rel="tag"># jar</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/12/10/tcpip/" rel="next" title="TCP/IP协议">
                <i class="fa fa-chevron-left"></i> TCP/IP协议
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2021/06/11/jni/" rel="prev" title="JNI开发">
                JNI开发 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.png" alt="Tonny Yi">
            
              <p class="site-author-name" itemprop="name">Tonny Yi</p>
              <p class="site-description motion-element" itemprop="description">Coding, Life, Zen</p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">49</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">42</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">59</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  <a href="https://github.com/tonnyyi" target="_blank" title="GitHub"><i class="fa fa-fw fa-github"></i>GitHub</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:tonnyemails@gmail.com" target="_blank" title="E-Mail"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  
                </span>
              
            </div>
          

          
          
            <div class="cc-license motion-element" itemprop="license">
              <a href="https://creativecommons.org/licenses/by-nc/4.0/" class="cc-opacity" target="_blank">
                <img src="/images/cc-by-nc.svg" alt="Creative Commons">
              </a>
            </div>
          

          
          

          
            
          
          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#jar命令"><span class="nav-number">1.</span> <span class="nav-text">jar命令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#查看jar包内容"><span class="nav-number">2.</span> <span class="nav-text">查看jar包内容</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#解压jar-war文件"><span class="nav-number">3.</span> <span class="nav-text">解压jar/war文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#打包jar-war文件"><span class="nav-number">4.</span> <span class="nav-text">打包jar/war文件</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#manifest文件"><span class="nav-number">4.1.</span> <span class="nav-text">manifest文件</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#manifest-mf文件规范"><span class="nav-number">4.1.1.</span> <span class="nav-text">manifest.mf文件规范</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#替换jar包内文件"><span class="nav-number">5.</span> <span class="nav-text">替换jar包内文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#其他"><span class="nav-number">6.</span> <span class="nav-text">其他</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Tonny Yi</span>

  

  
</div>


  <script src="https://unpkg.com/mermaid@7.1.2/dist/mermaid.min.js"></script>
  <script>
    if (window.mermaid) {
      mermaid.initialize("");
    }
  </script>





  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://theme-next.org">NexT.Mist</a></div>




        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=6.3.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.3.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.3.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=6.3.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.3.0"></script>



  



	





  





  










  





  

  

  

  

  
  

  

  

  

  

  
  <style>
    .copy-btn {
      display: inline-block;
      padding: 6px 12px;
      font-size: 13px;
      font-weight: 700;
      line-height: 20px;
      color: #333;
      white-space: nowrap;
      vertical-align: middle;
      cursor: pointer;
      background-color: #eee;
      background-image: linear-gradient(#fcfcfc, #eee);
      border: 1px solid #d5d5d5;
      border-radius: 3px;
      user-select: none;
      outline: 0;
    }

    .highlight-wrap .copy-btn {
      transition: opacity .3s ease-in-out;
      opacity: 0;
      padding: 2px 6px;
      position: absolute;
      right: 4px;
      top: 8px;
    }

    .highlight-wrap:hover .copy-btn,
    .highlight-wrap .copy-btn:focus {
      opacity: 1
    }

    .highlight-wrap {
      position: relative;
    }
  </style>
  <script>
    $('.highlight').each(function (i, e) {
      var $wrap = $('<div>').addClass('highlight-wrap')
      $(e).after($wrap)
      $wrap.append($('<button>').addClass('copy-btn').append('复制').on('click', function (e) {
        var code = $(this).parent().find('.code').find('.line').map(function (i, e) {
          return $(e).text()
        }).toArray().join('\n')
        var ta = document.createElement('textarea')
        document.body.appendChild(ta)
        ta.style.position = 'absolute'
        ta.style.top = '0px'
        ta.style.left = '0px'
        ta.value = code
        ta.select()
        ta.focus()
        var result = document.execCommand('copy')
        document.body.removeChild(ta)
        
          if(result)$(this).text('复制成功')
          else $(this).text('复制失败')
        
        $(this).blur()
      })).on('mouseleave', function (e) {
        var $b = $(this).find('.copy-btn')
        setTimeout(function () {
          $b.text('复制')
        }, 300)
      }).append(e)
    })
  </script>


</body>
</html>
